package com.czk.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/4/26 20:10
 */
@Data
public class OrderConfirmVo {
    // 地址列表
    @Getter
    @Setter
    private List<MemberAddressVo> address;
    // 所选中的购物项
    @Getter
    @Setter
    private List<OrderItemVo> items;
    // 优惠券信息
    @Getter
    @Setter
    private Integer integration;
    // 订单总额
    private BigDecimal total;
    // 防重复令牌
    private String orderToken;
    @Getter @Setter
    Map<Long,Boolean> stocks;
    private BigDecimal weight;
    public Integer getCount(){
        Integer i=0;
        if (items != null){
            for (OrderItemVo item : items) {
                // 计算
                i+=item.getCount();;
            }
        }
        return i;
    }
    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                // 计算
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                total.add(multiply);
            }
        }
        return total;
    }

    // 应付总额
    private BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        BigDecimal price = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                // 计算
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                total.add(multiply);
            }
        }
        return price;
    }
}
